package site.xuqing.autohelpertools;

import android.app.Activity;
import android.app.Application;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import site.xuqing.autohelperengine.AutoHelper;
import site.xuqing.autohelpertools.util.SharedPreferencesUtil;
import site.xuqing.autohelpertools.util.ToastUtil;

/**
 * @author XuQing
 */
public class App extends Application {
    private final List<Activity> activities=new ArrayList<>();
    private static App app;
    @Override
    public void onCreate() {
        super.onCreate();
        app=App.this;
        AutoHelper.getInstance().init(App.this);
        SharedPreferencesUtil.init(getApplicationContext());
        ToastUtil.init(getApplicationContext());
    }
    public static App getInstance(){
        return app;
    }

    public void addActivity(Activity activity){
        if (!activities.contains(activity))
            activities.add(activity);
    }

    public void removeActivity(Activity activity){
        activities.remove(activity);
    }

    public void clearAllActivity(){
        Iterator<Activity> iterator = activities.iterator();
        while (iterator.hasNext()) {
            Activity activity=iterator.next();
            iterator.remove();
            activity.finish();
        }
    }
}
